package o;

import android.content.Context;
import android.content.Intent;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import java.util.ArrayList;
import java.util.List;
import o.due.d;
import o.epq.e;

public class dub {
    private static boolean ॱ = false;
    private boolean ˊ = false;
    private List<ApkUpgradeInfo> ˎ = new ArrayList();
    private boolean ˏ = false;

    static class c implements d {
        private c() {
        }

        public void ॱ(SessionDownloadTask sessionDownloadTask) {
            if (sessionDownloadTask != null) {
                dvt.ˏ().ˏ(sessionDownloadTask);
            }
        }
    }

    private dub(boolean z) {
        this.ˎ.clear();
        this.ˏ = z;
    }

    public static boolean ˎ() {
        return ॱ;
    }

    public static void ˋ(boolean z) {
        ॱ = z;
    }

    public static void ˋ(boolean z, boolean z2) {
        if (ˎ()) {
            Logger.ˎ("BatchDownloadAppTask", "batchDownloadAppTask is running!");
            return;
        }
        ˋ(true);
        dub o_dub = new dub(z);
        o_dub.ॱ(z2);
        o_dub.ˋ();
    }

    private void ˋ() {
        Logger.ˎ("BatchDownloadAppTask", "run BatchDownloadAppTask.");
        Context ˋ = ContentManager.getInstant().getContext();
        this.ˎ.addAll(dss.ॱ().ˎ(true, 1));
        if (this.ˏ) {
            this.ˎ.addAll(dss.ॱ().ॱ(true, 1));
        }
        String packageName = ˋ.getPackageName();
        ApkUpgradeInfo apkUpgradeInfo = null;
        for (ApkUpgradeInfo apkUpgradeInfo2 : this.ˎ) {
            ApkUpgradeInfo apkUpgradeInfo22;
            if (!packageName.equals(apkUpgradeInfo22.ᐝ())) {
                ˏ(ˋ, apkUpgradeInfo22);
                apkUpgradeInfo22 = apkUpgradeInfo;
            }
            apkUpgradeInfo = apkUpgradeInfo22;
        }
        if (apkUpgradeInfo != null) {
            ˏ(ˋ, apkUpgradeInfo);
        }
        ˋ(false);
        ll.ˏ(ˋ).ˋ(new Intent(e.ˊ));
    }

    private void ˏ(Context context, ApkUpgradeInfo apkUpgradeInfo) {
        int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(apkUpgradeInfo.ᐝ());
        if (ˋ != 10 && ˋ != 11 && ˋ != 12 && ˋ != 13) {
            boolean ˊ;
            if (ˋ == 2 || ˋ == 1) {
                ˊ = ((ceq) cdb.ॱ(ceq.class)).ˊ(context, apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ʿ());
            } else {
                ˊ = false;
            }
            if (!ˊ) {
                ˋ(apkUpgradeInfo);
            } else if (apkUpgradeInfo.ˏॱ() == 0) {
                cnz ˏ;
                cnz o_cnz = cnz.ॱ;
                fhz ˋ2 = fho.ˏ().ˋ("PackageManager");
                if (ˋ2 != null) {
                    coa o_coa = (coa) ˋ2.ॱ(coa.class);
                    if (o_coa != null) {
                        ˏ = o_coa.ˏ(apkUpgradeInfo.ᐝ());
                        if (cnz.ॱ == ˏ) {
                            dsl.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ˊ(), apkUpgradeInfo.ॱᐝ(), 0, coc.ˎ);
                        }
                    }
                }
                ˏ = o_cnz;
                if (cnz.ॱ == ˏ) {
                    dsl.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ˊ(), apkUpgradeInfo.ॱᐝ(), 0, coc.ˎ);
                }
            }
        }
    }

    private void ˋ(ApkUpgradeInfo apkUpgradeInfo) {
        if (dok.ͺ()) {
            dvt.ˏ().ˊ(apkUpgradeInfo.ᐝ());
            dwk o_dwk = new dwk();
            SessionDownloadTask ˋ = dvt.ˏ().ˋ(apkUpgradeInfo.ᐝ());
            if (ˋ != null) {
                Logger.ˎ("BatchDownloadAppTask", "resumeDownload: " + apkUpgradeInfo.ᐝ());
                o_dwk.ˎ(ˋ, false);
                return;
            }
            Logger.ˎ("BatchDownloadAppTask", "startTask: " + apkUpgradeInfo.ᐝ());
            due.ॱ(apkUpgradeInfo, new c());
        }
    }

    private void ॱ(boolean z) {
        this.ˊ = z;
    }
}
